package org.wevil.repo.front;

import org.wevil.entity.front.SysMenuFront;
import org.wevil.entity.sys.SysMenu;
import org.wevil.repo.BaseRepo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysMenuFrontRepo extends BaseRepo<SysMenuFront, Integer> {

    @Query("select count(pid) from SysMenuFront where pid = ?1")
    Integer countByPid(Integer pid);

    @Query("from SysMenuFront where id in ?1")
    List<SysMenuFront> findByIdIn(List<Integer> ids);

    List<SysMenuFront> findByPid(Integer pid);

    @Modifying
    @Query("update SysMenuFront t set " +
            "t.name = case when :#{#entity.name} is null then t.name else :#{#entity.name} end, " +
            "t.url = case when :#{#entity.url} is null then t.url else :#{#entity.url} end, " +
            "t.pid = case when :#{#entity.pid} is null then t.pid else :#{#entity.pid} end, " +
            "t.sort = case when :#{#entity.sort} is null then t.sort else :#{#entity.sort} end, " +
            "t.icon = case when :#{#entity.icon} is null then t.icon else :#{#entity.icon} end " +
            "where t.id = :#{#entity.id}")
    int update(SysMenuFront entity);


}
